import tos
from tos import HttpMethodType

# Access key 和 Secret key 可在用户火山引擎账号中查找
ak = "AKLTMmFmMzVmNmY5ZDEyNDNmNWEyZTU2MDM3Y2EzMDJlZTk"
sk = "WVdNeFpXRXdNekV4Tm1ZME5EZGxPRGc0TUdFNE1HWXdNV1ZqTkdNNU9HRQ=="
# your endpoint 和 your region 填写Bucket 所在区域对应的Endpoint。# 以华北2(北京)为例，your endpoint 填写 tos-cn-beijing.volces.com，your region 填写 cn-beijing。
endpoint = "tos-cn-beijing.volces.com"
region = "cn-beijing"

def pre_signed_url(object_key,bucket_name,expires):
    #endpoint = 'tos-cn-beijing.ivolces.com'
    endpoint = 'tos-cn-beijing.volces.com'
    region = 'cn-beijing'
    tos_client = tos.TosClientV2(ak, sk, endpoint, region)
    pre_signed_url_output = tos_client.pre_signed_url(HttpMethodType.Http_Method_Get, bucket=bucket_name, key=object_key,expires=expires)
    if type(pre_signed_url_output.signed_url)==str and len(pre_signed_url_output.signed_url)>0:
        return pre_signed_url_output.signed_url
    else:
        return ''




if __name__ == '__main__':
    object_key="EP40/J3/MERGE_TRIGGER/v2309755506/20231201/8/fclkj01rc77u0nv7ulbi0-EP40_J3_drive_merge-trigger-20231201-085935-2013.tar.encrypted/IMAGE/EP40_J3_IMG/output.mp4"
    bucket_name="hz-trigger-parse"
    url = pre_signed_url(object_key, bucket_name, expires=3600 * 24 * 30)
    print(url)